<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">知识分类管理</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>知识库管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">知识分类管理</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      
     
    <div class="page-content" >
      		
		<div class="row"  style="width:auto;">
			
		       <div class="panel" style=" float:left; display:inline;  margin-left:15px; height: 600px; width:30%;  overflow: auto;">
				   <div class="panel-heading">知识分类管理树形菜单</div>
				    
				   <div class="panel-body">
					<ul id="tree" class="ztree" style="width:auto; overflow:auto;"></ul>
					<div id="dataNull" 
						style="height: 90px; line-height: 50px;" align="center">
					</div>
				   </div>
				</div>
				
		     <div class="col-lg-8" style=" display:inline; float:left; margin:0 20px 0 20px; height: 620px; width:60%;  overflow: auto;" >
	        	  <div class="panel" style="height: 600px;width:auto; overflow: auto;">
	                <div class="panel-heading">数据属性管理
	                </div>
						
							<div class="panel-body pan "style="width:auto; overflow: auto;" >
								<form action="#" class="form-horizontal">
									<div class="form-body pal" style="float:left;width:100%; overflow: auto;"  >
				
										<div style="margin:0 30px 0 -30px ; padding-bottom: 65px ;padding-top: 20px;" >
											<label for="inputUsername" class="col-md-3 control-label">
											  <div align="right">中文名称
												<span class='require' id="zhongwenName">*</span></div>
                                            </label>
											<div class="col-md-7">
												<div class="input-icon" >
													<input id="nameZh" type="text" class="form-control" value="" /><p id="nameZhTiShi"></p>
												</div>
											</div>
										</div>
				
				
										<div style="margin:0 30px 0 -30px; padding-bottom: 65px ;">
											<label for="inputUsername" class="col-md-3 control-label">
											  <div align="right">英文名称
												<span class='require' id="yingwenName">*</span></div>
                                            </label>
											<div class="col-md-7">
												<div class="input-icon">
													<input id="nameEn" type="text"  onchange="onPanduan(this.value);" class="form-control"  />
												</div>
											</div>
										</div>
										
										<div style="margin:0 30px 0 -30px ; padding-bottom: 65px;">
											<label for="inputUsername" class="col-md-3 control-label">
											  <div align="right">编号
												<span class='require' id="bianhao">*</span></div>
                                            </label>
											<div class="col-md-7">
												<div class="input-icon">
													<input id="cId" type="text" class="form-control" />
												</div>
											</div>
										</div>
						
										<div style="margin:0 30px 0 -30px ; padding-bottom: 65px;">
											<label for="inputUsername" class="col-md-3 control-label">
											  <div align="right">排序
												<span class='require' id="paixu">*</span></div>
                                            </label>
											<div class="col-md-7">
												<div class="input-icon">
													<input id="sort" type="text" class="form-control" />
												</div>
											</div>
										</div>
										<div style="margin:0 30px 0 -30px ; padding-bottom: 60px;">
											<label for="inputUsername" class="col-md-3 control-label">
											  <div align="right">父节点
												<span class='require' id="fuji"></span></div>
                                            </label>
											<div class="col-md-7">
												<div class="input-group input-group-sm mbs" >
													 <input id="domainName" type="text" placeholder="根目录" class="form-control" disabled="true"  />
													<span class="input-group-btn"><button id="xuanze" onclick="saveEditZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择类..</button></span>
												</div>
											</div>
										</div>
										<input id="id" type="hidden" class="form-control" />
										
										<input id="domainId" type="hidden" class="form-control" value="0"/>
										
										<div style="margin:0 30px 0 -30px ; padding-bottom: 60px;">
											<label for="inputUsername" class="col-md-3 control-label">
                                            </label>
											<div class="col-md-7">
												<div class="input-group input-group-sm mbs" >
													 <button type="button" onclick="Page()" class="btn btn-primary btn-blue"id="submit">
													保&nbsp;&nbsp;存
													</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
													<button type="button" onclick="shuaxin()" class="btn btn-primary btn-blue"id="submit">
														清&nbsp;&nbsp;空
													</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
													<button type="button" class="btn btn-primary btn-blue"
														id="deletejiedian">删&nbsp;&nbsp;除</button>
												</div>
											</div>
										</div>
									</div>	
								</form>
							</div>
					</div>
	        </div>
		</div>
    </div>	
     	
             	        
     <!--END CONTENT-->
 </div>
    
  
<?} ?>
<script>
	
	
	//树状结构
	$(function() {
		initTree();
	});

	var classid;
	var classname;
	var id="0";
	
	function initTree() {
		$.ajax({
			type : "post",
			data : {
				
			},
			url : "./domainCategoryZTree.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		if(data!="" && data!=null){
					$("#dataNull").html("");
		}else{
			$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
		}
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false,
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠
	}
	function onClick(e, treeId, treeNode) {
		
		classid = treeNode.id;
		classname=treeNode.name;
		demo1();
		 if(treeNode.children==null)
        {
       			parentname=0;
        }else{
         		parentname=1;
        }
		$("#id").val(classname);
	}
	
	$("#deletejiedian").click(function () { 
		if(classid!=null){
			del(classid);
		}else{
			alert("请选中节点");
		}
	});
	function del() {
		if(parentname==0)
	   {
			if (confirm("是否确认删除！！"))
			{
				$.ajax({
					type : "post",
					url : "./deldomain.do",
					data : {
						"id" : classid
					},
					dataType : "json",
					success : function(data) {
						if(data.count==1){
							layer.msg("删除成功！");
						}else{
							layer.msg("有关联的类，不可删除！");
						}
						shuaxin();
						initTree();
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}
		}else{
			alert("有子节点不允许删除");
		}
	}
	
	$("#editjiedian").click(function () { 
		if(classid!=null){
			
		}else{
			alert("请选中节点！！");
		}
	});
	
	
	function shuaxin(){
		$("#nameEn").attr("disabled", null);
		$("#id").val("0");
		$("#domainId").val("0");
		$("#nameZh").val("");
		$("#nameEn").val("");
		$("#cId").val("");
		$("#sort").val("");
		$("#domainName").val("");
	}
	
	
	function Page() {
		if($.trim($("#nameZh").val()).length<1) {
  	        	alert('中文不能为空！');
  	        	return null;
		}
		if ($.trim($("#nameEn").val()).length < 1) {
			alert('英文名称不能为空！');
			return null;
		}
		if ($.trim($("#cId").val()).length < 1) {
			alert('编号不能为空！');
			return null;
		}
		if ($.trim($("#sort").val()).length < 1) {
			alert('排序不能为空！');
			return null;
		}

		$.ajax({
			type : "post",
			url : "./domainSaveEdit.do",
			data : {
				"id" : $("#id").val(),
				"nameZh" : $("#nameZh").val(),
				"nameEn" : $("#nameEn").val(),
				"cId" : $("#cId").val(),
				"sort" : $("#sort").val(),
				"domainId" : $("#domainId").val()
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.initTree();
				shuaxin();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	function demo1() {
		$("#nameEn").attr("disabled", "true");
		id = classid;
		$.ajax({
			type : "post",
			url : "./domainEditfind.do",
			data : {
				"id" : id,
			},
			dataType : "json",
			success : function(res) {
				$("#id").val(res[0].id);
				$("#nameZh").val(res[0].nameZh);
				$("#nameEn").val(res[0].nameEn);
				$("#cId").val(res[0].cId);
				$("#sort").val(res[0].sort);
				$("#domainName").val(res[0].domainName);
				$("#domainId").val(res[0].PId);
			},
			error : function(res) {
				alert("请求失败");
			}
		});
	};

	function saveEditZTree() {
		layer.open({
			type : 2,
			area : [ '510px', '500px' ],
			fix : false, //不固定
			//maxmin : true,
			scrollbar : false,
			shadeClose : true,
			title : '知识分类',
			btn : [ '保存 ', '关闭' ],
			skin : 'layui-layer-rim', //加上边框
			content : "domain-save-edit-findall-zTree.html",
			yes : function(index, layer) {
				//alert(index);
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				//alert(iframeWin);
				iframeWin.queren();
			},
			cancel : function(index) {
			}
		});
	};
	
	function onPanduan(name){
			$.ajax({
				type : "post",
				url : "./domainPanDuan.do",
				data : {
					"nameEn" : $("#nameEn").val()
				},
				dataType : "json",
				async : false,
				success : function(data) {
					if(data[0].tishi=="英文名称不能重复"){
						alert("英文名称不能重复");
						$("#nameEn").val("");
					}
					if(data[0].geshi=="格式不正确"){
						alert("格式不正确!格式为： 英文【英文/下划线/数字】");
						$("#nameEn").val("");
					}
				}
			});
	}
</script>